package com.photography.service.impl;

import com.photography.mapper.ShootNumberMapper;
import com.photography.pojo.ShootNumber;
import com.photography.service.ShootNumberService;
import com.photography.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ShootNumberServiceImpl implements ShootNumberService {

    @Autowired
    private ShootNumberMapper shootNumberMapper;

    @Autowired
    private IdWorker idWorker;

    @Override
    public void addShootNumber(ShootNumber shootNumber) {
        shootNumber.setId(idWorker.nextId() + "");
        shootNumber.setCreated(new Date());
        shootNumber.setUpdated(shootNumber.getCreated());
        shootNumberMapper.insert(shootNumber);
    }
//
//    @Override
//    public PageResult<ShootNumber> findAll(int page, int rows) {
//        Page<ShootNumber> shootNumberPage = new Page<>(page, rows);
//        EntityWrapper<ShootNumber> wrapper = new EntityWrapper<>();
//        wrapper.eq("isstartusing",0).or().eq("isstartusing",1);
//        List<ShootNumber> shootNumbers = shootNumberMapper.selectPage(shootNumberPage, wrapper);
//        for (ShootNumber shootNumber:shootNumbers){
//            Category category = categoryMapper.selectById(shootNumber.getCategoryid());
//            shootNumber.setCategory(category);
//        }
//        shootNumberPage.setRecords(shootNumbers);
//        PageResult<ShootNumber> shootNumberPageResult = new PageResult<>();
//        shootNumberPageResult.setTotal(shootNumberPage.getTotal());
//        shootNumberPageResult.setRows(shootNumberPage.getRecords());
//        return shootNumberPageResult;
//    }

    @Override
    public void updateShootNumber(ShootNumber shootNumber) {
        shootNumber.setUpdated(new Date());
        shootNumberMapper.updateById(shootNumber);
    }

    @Override
    public void updateStatusShootNumbe(String[] ids, int status) {
        for(String id:ids){
            ShootNumber shootNumber = shootNumberMapper.selectById(id);
            if (status == 0){
                shootNumber.setIsstartusing(0);
            }else if (status == 1){
                shootNumber.setIsstartusing(1);
            }else if (status == 2){
                shootNumber.setIsstartusing(2);
            }
            shootNumberMapper.updateById(shootNumber);
        }
    }
}
